package test

import ninenineqs._

/**
  * Created by wyc on 6/11/2017.
  * Pack consecutive duplicates of list elements into sublists.
  * If a list contains repeated elements they should be placed in separate sublists.
  * Example:
  * scala> pack(List('a, 'a, 'a, 'a, 'b, 'c, 'c, 'a, 'a, 'd, 'e, 'e, 'e, 'e))
  * res0: List[List[Symbol]] = List(List('a, 'a, 'a, 'a), List('b), List('c, 'c), List('a, 'a), List('d), List('e, 'e, 'e, 'e))
  */

class test_p09 extends UnitSpec{
  feature(this.getClass.toString) {
    val L1 = List('a, 'a, 'a, 'a, 'b, 'c, 'c, 'a, 'a, 'd, 'e, 'e, 'e, 'e)
    val L2 = List[Any]()
    val L3 = List(4)
    val L4 = List(1 ,2, 3, 4)

    val Ts:List[(List[Any]) => List[Any]]=List(
      p09.pack_v1,
      p09.pack_v2,
      p09.pack_v3
    )

    var v = 1
    for ( func <- Ts ) {
      scenario("flatten_v" + v) {
        assert(func(L1) == List(List('a, 'a, 'a, 'a),
                                List('b), List('c, 'c), List('a, 'a),
                                List('d), List('e, 'e, 'e, 'e)))
        assert(func(L2) == List[Any]())
        assert(func(L3) == List(List(4)))
        assert(func(L4) == List(List(1), List(2), List(3), List(4)))
      }
      v += 1
    }
  }
}
